/**
  @(#)$Id: AL_SyncObj.cpp 69 2013-10-08 03:03:33Z xiaoting $
  @brief    	Multi-threaded programming critical section (lock)

  @author		$Author: xiaoting $
  @date			$Date: 2013-10-08 11:03:33 +0800 (周二, 08 十月 2013) $
  @version		$Revision: 69 $
  @url			$URL: https://svn.code.sf.net/p/xiaoting/game/trunk/MyProject/AL_StandardLib/AL_SyncObj.cpp $
  @header		$Header: https://svn.code.sf.net/p/xiaoting/game/trunk/MyProject/AL_StandardLib/AL_SyncObj.cpp 69 2013-10-08 03:03:33Z xiaoting $
 */
#include "stdafx.h"

#ifndef CXX_AL_SYNCOBJ_H
#include "AL_SyncObj.h"
#endif

// AL_ErrorLog Recording
static const NCHAR g_szErrorFileInfo[] = NTEXT("$Id: AL_SyncObj.cpp 69 2013-10-08 03:03:33Z xiaoting $");
///////////////////////////////////////////////////////////////////////////
//			AL_SyncObj
///////////////////////////////////////////////////////////////////////////

/*=============================================================================*/
/*Multi-threaded programming  synchronize (LINUX / WINDOWS)                                */
#if defined(_LINUX_AL_)
#include <pthread.h>
#include <sched.h>

/**
* Construction
*
* @param
* @return
*/
AL_SyncObj::AL_SyncObj()
{
	// Initialize mutex
	pthread_mutex_init(&m_mutex);
}

/**
* Destruction
*
* @param
* @return
*/
AL_SyncObj::~AL_SyncObj()
{
	// destroy mutex
	pthread_mutex_destroy(m_mutex);
}

/**
* SynchronizeStart
*
* @param VOID
* @return VOID
* @note
* @attention	used with SynchronizeEnd
*/
VOID 
AL_SyncObj::SynchronizeStart()
{
	// lock mutex
	pthread_mutex_lock(&m_mutex);
}

/**
* SynchronizeEnd
*
* @param VOID
* @return VOID
* @note
* @attention	used with SynchronizeStart
*/
VOID 
AL_SyncObj::SynchronizeEnd()
{
	// unlock mutex
	pthread_mutex_unlock(&m_mutex);
}

#else	// _LINUX_AL_

/**
* Construction
*
* @param
* @return
*/
AL_SyncObj::AL_SyncObj()
{
	// InitializeCriticalSection
	InitializeCriticalSection(&m_cs);
}

/**
* Destruction
*
* @param
* @return
*/
AL_SyncObj::~AL_SyncObj()
{
	// Delete critical section
	DeleteCriticalSection(&m_cs);
}

/**
* SynchronizeStart
*
* @param VOID
* @return VOID
* @note
* @attention	used with SynchronizeEnd
*/
VOID 
AL_SyncObj::SynchronizeStart()
{
	// Enter the critical region
	EnterCriticalSection(&m_cs);
}

/**
* SynchronizeEnd
*
* @param VOID
* @return VOID
* @note
* @attention	used with SynchronizeStart
*/
VOID 
AL_SyncObj::SynchronizeEnd()
{
	// Leave critical section
	LeaveCriticalSection(&m_cs);
}

#endif	// _WINDOWS_AL_

/* EOF */